package ru.paswd.marketprice.storage.receipt.api;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;
import ru.paswd.marketprice.storage.receipt.api.dto.EditableReceipt;
import ru.paswd.marketprice.storage.receipt.api.dto.FiscalId;
import ru.paswd.marketprice.storage.receipt.api.dto.Receipt;
import ru.paswd.marketprice.storage.receipt.api.dto.ReceiptItem;
import ru.paswd.marketprice.storage.receipt.api.dto.ReceiptSerialized;

import java.util.List;

@Api(tags = "Receipt")
@RequestMapping("/api/v1/receipt")
public interface ReceiptStorageApi {
    @ApiOperation("Get all receipts")
    @ApiResponses({
            @ApiResponse(code = 200, message = "OK"),
            @ApiResponse(code = 500, message = "Internal server error")
    })
    @GetMapping("list")
    Page<Receipt> getAllReceipts(Pageable pageable);

    @ApiOperation("Get receipt by fiscal params")
    @ApiResponses({
            @ApiResponse(code = 200, message = "OK"),
            @ApiResponse(code = 500, message = "Internal server error")
    })
    @GetMapping("single")
    Receipt getReceiptByParams(
            @RequestParam("fiscalNumber") String fiscalNumber,
            @RequestParam("fiscalSign") String fiscalSign,
            @RequestParam("fiscalDocumentNumber") String fiscalDocumentNumber
    );

    @ApiOperation("Add receipt")
    @ApiResponses({
            @ApiResponse(code = 200, message = "OK"),
            @ApiResponse(code = 500, message = "Internal server error")
    })
    @PutMapping("add")
    void addReceipt(@RequestBody Receipt receipt);

    @ApiOperation("Add receipt list")
    @ApiResponses({
            @ApiResponse(code = 200, message = "OK"),
            @ApiResponse(code = 500, message = "Internal server error")
    })
    @PutMapping("addList")
    void addReceipts(@RequestBody List<Receipt> receipts);

    @ApiOperation("Add receipt")
    @ApiResponses({
            @ApiResponse(code = 200, message = "OK"),
            @ApiResponse(code = 500, message = "Internal server error")
    })
    @PutMapping("addSerialized")
    void addReceiptSerialized(@RequestBody ReceiptSerialized receipt);

    @ApiOperation("Add receipt list")
    @ApiResponses({
            @ApiResponse(code = 200, message = "OK"),
            @ApiResponse(code = 500, message = "Internal server error")
    })
    @PutMapping("addSerizlizedList")
    void addReceiptsSerialized(@RequestBody List<ReceiptSerialized> receipts);

    @ApiOperation("Update receipt")
    @ApiResponses({
            @ApiResponse(code = 200, message = "OK"),
            @ApiResponse(code = 500, message = "Internal server error")
    })
    @PostMapping("update")
    void updateReceipt(
            @RequestBody EditableReceipt receipt
    );

    @ApiOperation("Remove receipt by fiscal params")
    @ApiResponses({
            @ApiResponse(code = 200, message = "OK"),
            @ApiResponse(code = 500, message = "Internal server error")
    })
    @DeleteMapping("remove")
    void removeReceipt(
            @RequestBody FiscalId fiscalId
    );

    @ApiOperation("Add receipt item")
    @ApiResponses({
            @ApiResponse(code = 200, message = "OK"),
            @ApiResponse(code = 500, message = "Internal server error")
    })
    @PutMapping("addItem")
    void addItem(
            @RequestParam("fiscalNumber") String fiscalNumber,
            @RequestParam("fiscalSign") String fiscalSign,
            @RequestParam("fiscalDocumentNumber") String fiscalDocumentNumber,
            @RequestBody ReceiptItem receiptItem
    );

    @ApiOperation("Remove receipt item")
    @ApiResponses({
            @ApiResponse(code = 200, message = "OK"),
            @ApiResponse(code = 500, message = "Internal server error")
    })
    @DeleteMapping("removeItem")
    void removeItem(
            @RequestParam("fiscalNumber") String fiscalNumber,
            @RequestParam("fiscalSign") String fiscalSign,
            @RequestParam("fiscalDocumentNumber") String fiscalDocumentNumber,
            @RequestParam(value = "name", required = false) String name
    );
}
